<%-- 
    Document   : index
    Created on : 2016-6-28, 12:09:22
    Author     : 52461
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="../link.jsp"%>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript" src="${base}/js/highcharts/highcharts.js" ></script>
        <script type="text/javascript" src="${base}/js/mychartoption.js" ></script>
        <style>
            .tab{
                margin-left:20px;
                width:500px;
                /*border-collapse:collapse;*/
                /*border:1px dashed;*/
            }/*
            .tab th, .tab td {
                 border:1px dashed;
                 padding:0px;
            }*/
            .yb{
                float:left;
            }
            table th{
                white-space: nowrap;
            }
            table td{
                white-space: nowrap;
            }

            .autoInput{
                border: none;
                border-bottom: 1px violet solid;
                width: 100%;
                height: 30px;
                outline: none;
                background: transparent;
            }
            input:disabled{

                background-color:#ffffff
            }

            .reslut>.table>tbody>tr>td{
                padding-top: 1px;
                padding-bottom: 1px;

            }


        </style>
        <title>JSP Page</title>
    </head>
    <body ng-app='hostApp' ng-controller="hostCtrl" style="font-family: 微软雅黑;height: 100%;overflow-y: hidden">
        <div class="hbox hbox-auto-xs hbox-auto-sm ng-scope" style="height: 100%;overflow-y: hidden">
            <!-- .col -->
            <div class="col w-lg bg-light dk b-r bg-auto" id="aside" style="background-color: #ffffff;">
                <div class="wrapper bg b-b" style="height: 48px;">
                    <!--<button class="btn btn-sm btn-success pull-right" ui-toggle-class="timeline-center" target=".timeline">Center</button>-->
                    <h4 style="float: left" class="m-n font-thin">详细信息</h4>
                    <button class="btn btn-success btn-sm" ng-click="getList()" style="float: right" title="刷新"><i class="fa fa-refresh"></i><span id="time"></span></button>
                </div>
                <div class="wrapper" style="padding: 0px;padding-left: 10px;padding-right: 2px; height: 100%;" >
                    <!--                    <div>
                                            <button class="btn m-b-xs btn-sm btn-success btn-addon" id="xiugai">修改病人信息</button>
                                            <button class="btn m-b-xs btn-sm btn-success btn-addon" id="quxiao" style="display:none">取消</button>
                                        </div>-->
                    <ul id="myTab2" class="nav nav-tabs">
                        <li class="active">
                            <a href="#view-user" data-toggle="tab">
                                病人登记
                            </a>
                        </li>
                        <li><a href="#view-userList" data-toggle="tab">
                                病人列表
                            </a>
                        </li>

                    </ul>

                    <div id="myTabContent" class="tab-content" style="height: 800px;overflow: auto">
                        <div class="tab-pane fade in active" id="view-user">
                            <form name="patInfo" class="ng-pristine ng-valid">
                                <table style="width:100%" >
                                    <tr>
                                        <td >样本日期</td>
                                        <td>
                                            <div style="position: relative;">
                                                <input ng-change="changeSampleDate()" type="text" class="form-control " id="sample_date" ng-model="sample_date"  >
                                                <a ><i style="position: absolute;right: 2px; top: 10px;" class="fa fa-calendar"></i></a>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td >样&nbsp;本&nbsp;&nbsp;号</td>
                                        <td><input type="text" class="form-control "  ng-model="ybh" readonly></td>
                                    </tr>
                                    <tr>
                                        <td>条&nbsp;码&nbsp;&nbsp;号</td>
                                        <td>
                                            <div style="position: relative;">
                                                <input type="text" class="form-control " id="tmh" ng-model="info.BARCODE" ng-keydown="searchBarcode($event)" >
                                                <a ng-click="searchBar()"><i style="position: absolute;right: 2px; top: 10px;" class="fa fa-search"></i></a>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>病人类型</td>
                                        <td valign="middle" style="padding-top: 12px; line-height: 25px;border-bottom: 1px #dee5e7 solid" >&nbsp;&nbsp;&nbsp;<label><input type="radio" name="lx" class=" cs" ng-model="info.STAYHOSPITALMODE" value="门诊"/>门诊</label>
                                            &nbsp;&nbsp;&nbsp;
                                            <label><input type="radio" name="lx" class=" cs"  ng-model="info.STAYHOSPITALMODE" value="住院"/>住院</label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>病&nbsp;历&nbsp;&nbsp;号</td>
                                        <td>
                                            <div style="position: relative;">
                                                <input type="text" class="form-control " id="zyh" ng-model="info.PATIENTID" ng-keydown="searchPatientId($event)" >
                                                <a ng-click="searchPid()"><i style="position: absolute;right: 2px; top: 10px;" class="fa fa-search"></i></a>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名</td>
                                        <td><input type="text" class="form-control cs key" ng-model="info.PATIENTNAME" required="" /></td>
                                    </tr>
                                    <tr>
                                        <td>性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别</td>
                                        <!--                                <td style="padding-top: 12px; line-height: 25px;border-bottom: 1px #dee5e7 solid">
                                                                            &nbsp;&nbsp;&nbsp;
                                                                                                                <label>
                                                                                                                    <input type="radio" name="sex" class=" cs" required="" ng-model="info.SEX" value="男"/>男</label>
                                                                                                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                                                                                <label><input type="radio" name="sex" class=" cs"  ng-model="info.SEX" required="" value="女"/>女</label>
                                                                           
                                                                        </td>-->
                                        <td>
                                            <select ng-change="changeSex(info.SEX)" ng-model="info.SEX" class="form-control cs key ">
                                                <option   value="男">男</option>
                                                <option  value="女">女</option>
                                            </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>年&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;龄</td>
                                        <td><input type="text" class="form-control cs key" required="" ng-model="info.AGE" /></td>
                                    </tr>
                                    <tr>
                                        <td>科&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;室</td>
                                        <td><input  type="text" class="form-control cs key" ng-model="info.SECTION" />
                                            <!--                                        <option ng-repeat="ks in ksmcs">{{ks.KSMC}}</option>-->

                                        </td>
                                    </tr>
                                    <tr>
                                        <td>床&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号</td>
                                        <td><input type="text" class="form-control cs key" ng-model="info.BED_NO" /></td>
                                    </tr>
                                    <tr>
                                        <td>检验项目</td>
                                        <td>
                                            <input class="form-control cs key" ng-model="info.EXAMINAIM" />
                                            <!--                                        <option ng-repeat="xm in xms">{{xm.ITEMNAME}}</option>-->
                                            <!--                                    </select>-->
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>标本类型</td>
                                        <td><select class="form-control cs key" ng-model="info.SAMPLE" >
                                                <option ng-repeat="sa in samp">{{sa.SAMPLEDESCRIBE}}</option>
                                            </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>检验医生</td>
                                        <td>

                                            <select class="form-control cs key" ng-model="info.JYYS" ng-options="x.name as x.name for x in user"></select>
                                            <!--                                    <select class="form-control cs" ng-model="info.JYYS" >
                                                                                    <option ng-repeat="u in user">{{u.name}}</option>
                                                                                </select>-->
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>送检医生</td>
                                        <td>
                                            <input type="text" class="form-control key" ng-model="info.SJYS"  />

                                            <!--                                    <select class="form-control cs" ng-model="info.SJYS" >
                                                                                    <option ng-repeat="u in user">{{u.name}}</option>
                                                                                </select>-->
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>审核医生</td>
                                        <td><input type="text" class="form-control " ng-model="info.CHECKOPERATOR" readonly /></td>
                                    </tr>
                                    <tr>
                                        <td>采样时间</td>
                                        <td><input type="text" class="form-control " ng-model="info.CYSJ" readonly /></td>
                                    </tr>
                                    <tr>
                                        <td>送检时间</td>
                                        <td><input type="text" class="form-control" ng-model="info.CUSTOM1" /></td>
                                    </tr>
                                    <tr>
                                        <td>打印时间</td>
                                        <td><input type="text" class="form-control" ng-model="info.PRINTTIME" readonly /></td>
                                    </tr>
                                    <tr>
                                        <td>临床诊断</td>
                                        <td><input type="text" class="form-control cs key" ng-model="info.DIAGNOSTIC" /></td>
                                    </tr>
                                    <!--                                    <tr>
                                                                            <td>自定义类别</td>
                                                                            <td>
                                                                                <select class="form-control c keys" ng-model="info.SELF_TYPE" >
                                                                                    <option ng-repeat="u in self_type">{{u}}</option>
                                                                                </select>
                                    
                                                                            </td>
                                                                        </tr>
                                    -->                                                                        <tr>
                                        <td>试剂</td>
                                        <td>
                                            <select class="form-control cs key" ng-model="zk_REAGENT" ng-options="x.BATCH_NUMBER for x in phs"></select>
                                            <!--                                                                                                                    <input type="text" class="form-control cs" ng-model="info.DIAGNOSTIC" />-->
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>温度</td>
                                        <td>
                                            <input type="text" class="form-control cs key" ng-model="info.ROOM_TEMPERATURE" />                          
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>备注</td>
                                        <td>
                                            <input type="text" class="form-control cs key" ng-model="info.CUSTOM2" />                          
                                        </td>
                                    </tr>
                                </table>
                            </form>
                        </div>
                        <div class="tab-pane " id="view-userList">
                            <table class="table table-striped table-responsive table-condensed">
                                <tr ng-repeat="item in pats">
                                    <td ng-bind="item.SAMPLENO"></td>                                  
                                    <td ng-bind="item.PATIENTNAME"></td>
                                    <td ng-bind="item.SEX"></td>
                                    <td ng-bind="item.AGE"></td>
                                </tr>
                            </table>
                        </div>
                    </div>

                </div>
            </div>
            <!-- /.col -->
            <!-- .col -->
            <div class="col">

                <!--      <div class="wrapper"style="display: table-row;height: 100%;height: 100%">-->
                <table style="width: 100%;height: 100%" >
                    <tr>
                        <td style="height:48px;">
                            <span class="autoFilter">筛选条件</span>
                            <select ng-change="getList()"  ng-model="status" style="width:60px; background-color: transparent" >
                                <option value="0">所有</option>
                                <option value="1">未审核</option>
                                <!--                                <option value="2">未打印</option>-->
                                <option value="2">已审核</option>
                                <option value="3">已打印</option>
                                <option value="5">无结果</option>
                            </select>
                            <span class="autoFilter">检验设备</span>
                            <select ng-disabled="searchTypeStatus" style="width:200px;background-color: transparent" ng-model="deed" ng-options="de.DEVICEMODEL as (de.DEVICEMODEL +                                        de.DEVICENAME) for de in des" ng-change="changeType()" ></select>

                            <!--                            <label>&nbsp;所有&nbsp;</label><input name="filter" value="all" type="radio" checked ng-click="getList()"/>
                                                        <label>未审核&nbsp;</label><input name="filter" value="all" type="radio" ng-click="getNoShenHe()" />
                                                        <label>未打印&nbsp;</label><input name="filter" value="all" type="radio" />
                                                        <label>已审核&nbsp;</label><input name="filter" value="all" type="radio" ng-click="getShenHe()"/>
                                                        <label>已打印&nbsp;</label><input name="filter" value="all" type="radio" ng-click="getDaYin()"/>
                                                        <label>无结果&nbsp;</label><input name="filter" value="all" type="radio" ng-click="getNoResult()"/>-->
                        </td>
                        <td>
                            <!--                            <button class="btn m-b-xs btn-sm btn-info" ng-click="hebing()">合并</button>-->
                            <button class="btn m-b-xs btn-sm btn-info" ng-click="shougong()">手工</button>
                            <button class="btn m-b-xs btn-sm btn-info" ng-show="sgstatus" ng-click="savesg()">生成多条手工记录</button>
                            <button class="btn m-b-xs btn-sm btn-primary" ng-click="saveZkData()">保存为质控</button>

                            <button class="btn m-b-xs btn-sm btn-success btn-addon" ng-click="saveInfo(patInfo)"><i class="fa fa-save"></i>保存</button>
                            <button class="btn m-b-xs btn-sm btn-danger btn-addon" ng-click="deleteInfo()"><i class="fa fa-plus"></i>删除</button>
                            <button class="btn m-b-xs btn-sm btn-primary btn-addon" ng-click="piLiangSH()"><i class="fa fa-plus"></i>审核</button>
                            <button ng-show="sh_status" class="btn m-b-xs btn-sm btn-danger btn-addon" ng-click="cancelSH()">取消审核</button>
                            <button class="btn m-b-xs btn-sm btn-primary btn-addon" ng-click="insertOne()">添加项目</button>
                            <button class="btn m-b-xs btn-sm btn-primary btn-addon" ng-click="openZT()">添加组套</button>
                            <button class="btn m-b-xs btn-sm btn-info btn-addon" ng-click="printJG()"><i class="fa fa-print"></i>打印</button>
                        </td>
                    </tr>
                    <tr>
                        <td class="autoWidthPatList" style="border-right: 1px solid #dee5e7;">
                            <div class="autoWidthPatList" style="height: 100%;overflow: auto">
                                <table class="table table-bordered xl_info">
                                    <tr>
                                        <th><input type="checkbox" ng-model="checkAll" ng-change="checked()"></th>
                                        <th>样本号</th>
                                        <th>姓名</th>
                                        <th>性别</th>
                                        <th>状态</th>
                                        <th>年龄</th>
                                        <th>类型</th>
                                        <th>科室</th>
                                        <th>床号</th>
                                        <th>送检医生</th>
                                    </tr>
                                    <tr ng-repeat="list in lists"  id="do">
                                        <td id="td1"><input type="checkbox" ng-model="list.check" name="btn"></td>
                                        <td ng-click="getResult(list, $event, $index)" ng-bind="list.SAMPLENO"></td>
                                        <td ng-click="getResult(list, $event, $index)" ng-bind="list.PATIENTNAME"></td>
                                        <td ng-click="getResult(list, $event, $index)" ng-bind="list.SEX"></td>
                                        <td ng-click="getResult(list, $event, $index)" ng-bind="list.RESULTSTATUS" ng-class="{true: 'text - info', false:'text - success'}[list.active]"></td>
                                        <td ng-click="getResult(list, $event, $index)" ng-bind="list.AGE" ></td>
                                        <td ng-click="getResult(list, $event, $index)" ng-bind="list.STAYHOSPITALMODE" ></td>
                                        <td ng-click="getResult(list, $event, $index)" ng-bind="list.SECTION" ></td>
                                        <td ng-click="getResult(list, $event, $index)" ng-bind="list.BED_NO" ></td>
                                        <td ng-click="getResult(list, $event, $index)" ng-bind="list.SJYS" ></td>
                                    </tr>
                                </table>
                            </div>




                        </td>
                        <td valign="top" >
                            <ul id="myTab" class="nav nav-tabs">
                                <li class="active">
                                    <a href="#view-data" data-toggle="tab">
                                        数据
                                    </a>
                                </li>
                                <li><a href="#view-chart" data-toggle="tab">
                                        直方图
                                    </a>
                                </li>

                            </ul>

                            <div id="myTabContent" class="tab-content" style="height: 800px;overflow-y: auto;overflow-x: hidden">
                                <div class="tab-pane fade in active" id="view-data">

                                    <div class="reslut" style="width: 100%;margin-left: 10px;border-left: 1px solid #dee5e7; overflow: auto">
                                        <table class="table table-bordered">
                                            <tr id="tr1">
                                                <th>序号</th>
                                                <th>代码</th>
                                                <th>检验项目</th>
                                                <th></th>
                                                <th>结果</th>
                                                <th>单位</th>
                                                <th>范围</th>
                                                <th>其他</th>
                                            </tr>
                                            <tr ng-show="result.RESULTFLAG == '0'" ng-repeat="result in results" ng-click="djResult(result, $event, $index)" id="dp" ng-class="{true: 's_danger', false: 's_warning'}[result.isActive]">
                                                <td>{{$index + 1}}</td>
                                                <td>{{result.TESTID}}</td>
                                                <td>
                                                    <input myindex="{{$index}}" ng-model="result.CHINESENAME"   class="autoInput xx"/>
                                                </td>
                                                <td style="width:10px;">{{result.HL_STATUS}}</td>
                                                <td>
                                                    <input myindex="{{$index}}" class="autoInput yy" autoSearch="{{result.TESTID}}"  ng-change="changeResultStatus($index)" ng-model="result.TESTRESULT">
                                                </td>

                                                <td>{{result.UNIT}}</td>
                                                <td>{{result.fanwei}}</td>
                                                <td ng-click="deleteXM(result, $index)"><span class="fa fa-close " style="color:red"></span></td>
                                            </tr>
                                        </table>
                                    </div>
                                </div>
                                <div class="tab-pane fade" id="view-chart">
                                    <div ng-hide="zftchart">
                                        <div ng-show="sh_baso" id="baso"  style="width:300px;height: 300px;"></div>
                                        <div ng-show="sh_diff" id="diff"  style="width:300px;height: 300px;"></div>
                                        <div ng-show="sh_wbc" id="wbc"  style="width:600px;height: 250px;">

                                        </div>

                                        <div ng-show="sh_rbc" id="rbc"  style="width:600px;height: 250px;"></div>
                                        <div ng-show="sh_plt" id="plt"  style="width:600px;height: 250px;"></div>


                                    </div>
                                    <div ng-show="zftchart">
                                        <div  ng-show="sh_wbc" style="width:600px;height: 200px">
                                            <label>WBC</label>
                                            <img ng-src="{{WBC}}" />
                                        </div>

                                        <div  ng-show="sh_rbc" style="width:600px;height: 200px; margin-bottom: 20px">
                                            <label>RBC</label>
                                            <img ng-src="{{RBC}}" />
                                        </div>

                                        <div ng-show="sh_plt"  style="width:600px;height: 200px;margin-bottom: 20px">
                                            <label>PLT</label>
                                            <img ng-src="{{PLT}}" />
                                        </div>
                                        <div ng-show="sh_diff"  style="width:600px;height: 200px;margin-bottom: 20px">
                                            <label>DIFF</label>
                                            <img ng-src="{{DIFF}}" />
                                        </div>
                                        <div  ng-show="sh_baso"  style="width:600px;height: 200p;margin-bottom: 20px">
                                            <label>BASO</label>
                                            <img ng-src="{{BASO}}" />
                                        </div>
                                        <div  ng-show="sh_sret"  style="width:600px;height: 300px;margin-bottom: 20px">
                                            <label>SRET</label>
                                            <img ng-src="{{SRET}}" />
                                        </div>
                                        <div  ng-show="sh_swdf"  style="width:600px;height: 300px;margin-bottom: 20px">
                                            <label>SWDF</label>
                                            <img ng-src="{{SWDF}}" />
                                        </div>
                                        <div  ng-show="sh_swnr"  style="width:600px;height: 300px;margin-bottom: 20px">
                                            <label>SWNR</label>
                                            <img ng-src="{{SWNR}}" />
                                        </div>

                                    </div>
                                    <div ng-show="image_more">
                                        <div ng-repeat="image in moreImage" style="width:600px;height: 200px;margin-top: 20px">

                                            <img height="200px" ng-src="{{image}}" />
                                        </div>


                                    </div>

                                </div>

                            </div>



                        </td>
                    </tr>
                    <tr>
                        <td style="height: 35px; border-top: 1px solid #dee5e7;border-right: 1px solid #dee5e7;"><span style="font-weight: bold" ng-bind="lists.length"></span></td>
                        <td style=" border-top: 1px solid #dee5e7;">状态</td>
                    </tr>
                </table>
                <!--</div>-->
            </div>
            <!-- /.col -->            
        </div>

        <!-- 密码验证 -->
        <div class="modal fade mode-x" id="mode2" role="dialog" aria-labelledby="gridSystemModalLabel">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close" ng-click="CloseModel()"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="gridSystemModalLabel">密码验证</h4>
                    </div>
                    <div class="modal-body">
                        <table>
                            <tr>
                                <td>请输入您的登录密码:<input type="password" ng-model="mm"></td>
                            </tr>
                        </table>

                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal" ng-click="CloseModel()">关闭</button>
                        <button  ng-click="checkMm()"  type="button" class="btn btn-primary"><span class="fa fa-save"></span>&nbsp;&nbsp;确定</button>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->

        <!--添加组套--> 
        <div class="modal fade mode-x" id="mode3" role="dialog" aria-labelledby="gridSystemModalLabel">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close" ng-click="CloseModel()"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="gridSystemModalLabel">添加组套</h4>
                    </div>
                    <div class="modal-body" style="height: 400px; overflow: auto">
                        <table class="table  table-bordered">
                            <tr>
                                <td>序号</td>
                                <td>组套名称</td>
                            </tr>
                            <tr ng-repeat="zt in zts" ng-click="clickZT(zt, $event)">
                                <td>{{$index + 1}}</td>
                                <td>{{zt.ITEMNAME}}</td>
                            </tr>
                        </table>

                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-danger" data-dismiss="modal" ng-click="CloseModel()">关闭</button>
                        <button  ng-click="addZT('replace')"  type="button" class="btn btn-primary"><span class="fa fa-save"></span>&nbsp;&nbsp;替换</button>
                        <button  ng-click="addZT('add')"  type="button" class="btn btn-primary"><span class="fa fa-save"></span>&nbsp;&nbsp;添加</button>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div>



        <div class="modal fade modal-info" id="mode4" role="dialog" aria-labelledby="gridSystemModalLabel">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                        <h4 class="modal-title">信息列表</h4>
                    </div>
                    <div class="modal-body">
                        <table class="table table-bordered table-striped">
                            <tr ng-dblclick="selectInfo(info)" ng-repeat="info in infos">
                                <td>{{info.PATIENTID}}</td>
                                <td>{{info.PATIENTNAME}}</td>
                                <td>{{info.SEX}}</td>
                                <td>{{info.AGE}}</td>
                                <td>{{info.EXAMINAIM}}</td>
                            </tr>
                        </table>
                    </div>


                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->


        <div class="modal fade modal-sg" id="" role="dialog" aria-labelledby="gridSystemModalLabel">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                        <h4 class="modal-title">数量</h4>
                    </div>
                    <div class="modal-body">
                        <input type="number" required="" class="form-control" ng-model="sg_count" />
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-danger" data-dismiss="modal" >关闭</button>
                        <button  ng-click="save_sg_to_server()"  type="button" class="btn btn-primary"><span class="fa fa-save"></span>&nbsp;&nbsp;保存</button>

                    </div>

                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->

        <div class="modal fade sg_device" id="" role="dialog" aria-labelledby="gridSystemModalLabel">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                        <h4 class="modal-title">手工设备</h4>
                    </div>
                    <div class="modal-body" style="text-align: center">
                        <select ng-model="sgDevice"  ng-change="changeSgDevice()" ng-options="x.DEVICEMODEL for x in sgDevices" style="width:200px" class="form-control" >

                        </select>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-danger" data-dismiss="modal" >关闭</button>
                        <!--<button  ng-click="save_sg_to_server()"  type="button" class="btn btn-primary"><span class="fa fa-save"></span>&nbsp;&nbsp;保存</button>-->

                    </div>

                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->

    </body>
</html>
<script>
    angular.module("hostApp", ['baseModule'])
            .controller("hostCtrl", function ($scope, base) {
                $scope.filterData = "0";
                $scope.deed = "0";
                $scope.sgstatus = false;
                $scope.info = {};
                $scope.info.SEX = "男";
                $scope.resultItem = {DEVICEID: "MB"};
                $scope.sample_date = new Date().Format("yyyy-MM-dd") + "";
                $scope.self_type = config.hisChartTitle;
                if ($scope.self_type && $scope.self_type.length > 5) {
                    $scope.self_type = $scope.self_type.split("@");
                }
                $scope.results = [];
                var WBC = [];
                var RBC = [];
                var PLT = [];
                var BASO = [];
                var DIFF = [];
                var SRET = [];
                var SWDF = [];
                var SWNR = [];
                $scope.changeZt = function (data) {
                    for (var i = 0; i < data.length; i++) {
                        if (data[i].RESULTSTATUS == "0") {
                            data[i].RESULTSTATUS = "无结果";
                        }
                        if (data[i].RESULTSTATUS == "1" || data[i].RESULTSTATUS == null) {
                            data[i].RESULTSTATUS = "未审核";
                        }
                        if (data[i].RESULTSTATUS == "2") {
                            data[i].RESULTSTATUS = "已审核";
                            data[i].active = true;
                        }
                        if (data[i].RESULTSTATUS == "3") {
                            data[i].RESULTSTATUS = "已打印";
                            data[i].active = false;
                        }
                    }
                }
                $scope.changeSex = function (sex) {
                    if (sex && sex == '女') {
                        if ($scope.results) {
                            for (i in $scope.results) {
                                if ($scope.results[i].MREFLO0) {
                                    var lower = $scope.results[i].MREFLO0;
                                    var hight = $scope.results[i].MREFHI0;
                                    if ($scope.results[i].FREFLO0 && $scope.results[i].FREFLO0 != "") {
                                        lower = $scope.results[i].FREFLO0;
                                        hight = $scope.results[i].FREFHI0;
                                    }
                                    var lh = lower + "-" + hight;
                                    $scope.results[i].fanwei = lh;

                                    if (parseFloat($scope.results[i].TESTRESULT) < parseFloat(lower)) {
                                        //console.log(data[i].TESTRESULT + "   " + data[i].MREFLO0);
                                        $scope.results[i].isActive = true;
                                        $scope.results[i].HL_STATUS = "↓"
                                    } else if (parseFloat($scope.results[i].TESTRESULT) > parseFloat(hight)) {
                                        $scope.results[i].isActive = false;
                                        $scope.results[i].HL_STATUS = "↑"

                                    } else {
                                        $scope.results[i].isActive = null;
                                        $scope.results[i].HL_STATUS = "";
                                    }
                                }
                            }
                        }
                    } else {
                        if ($scope.results) {
                            for (i in $scope.results) {
                                if ($scope.results[i].MREFLO0) {
                                    var lower = $scope.results[i].MREFLO0;
                                    var hight = $scope.results[i].MREFHI0;

                                    var lh = lower + "-" + hight;
                                    $scope.results[i].fanwei = lh;
                                    if (parseFloat($scope.results[i].TESTRESULT) < parseFloat(lower)) {
                                        //console.log(data[i].TESTRESULT + "   " + data[i].MREFLO0);
                                        $scope.results[i].isActive = true;
                                        $scope.results[i].HL_STATUS = "↓"
                                    } else if (parseFloat($scope.results[i].TESTRESULT) > parseFloat(hight)) {
                                        $scope.results[i].isActive = false;
                                        $scope.results[i].HL_STATUS = "↑"

                                    } else {
                                        $scope.results[i].isActive = null;
                                        $scope.results[i].HL_STATUS = "";
                                    }
                                }
                            }
                        }
                    }
                }
                $scope.getList = function () {
                    base.post("host/getList", {sample_date: $scope.sample_date, status: $scope.status, device: $scope.device}).get(function (data) {
                        $scope.changeZt(data);
                        $scope.lists = data;

                    });
                }
                $scope.changeSampleDate = function () {
                    $scope.getList();
                }
                $scope.getList();
                $scope.getShenHe = function () {
                    base.post("host/getShenHe").get(function (data) {
                        $scope.changeZt(data);
                        $scope.lists = data;
                    });
                }
                $scope.getNoShenHe = function () {
                    base.post("host/getNoShenHe").get(function (data) {
                        $scope.changeZt(data);
                        $scope.lists = data;
                    });
                }
                $scope.getDaYin = function () {//打印
                    base.post("host/getDaYin").get(function (data) {
                        $scope.changeZt(data);
                        $scope.lists = data;
                    });
                }
                $scope.getNoResult = function () { //无结果
                    base.post("host/getNoResult").get(function (data) {
                        $scope.changeZt(data);
                        $scope.lists = data;
                    });
                }
                $scope.getKsmc = function () {
                    $.post("host/getKsmc", function (data) {
                        $scope.ksmcs = data;
                        $scope.$apply();
                    })
                }
                $scope.getKsmc();
                $scope.getSample = function () {
                    $.post("host/getSample", function (data) {
                        $scope.samp = data;
                        $scope.$apply();
                    })
                }
                $scope.getSample();
                $scope.getUser = function () {
                    $.post("host/getUser", function (data) {
                        $scope.user = data;
                        $scope.$apply();
                    })
                }
                $scope.getUser();
                $scope.getDeviceType = function () {
                    $.post("host/getType", function (data) {
                        $scope.des = data;
                        if ($scope.des) {
                            $scope.des.push({"DEVICEMODEL": "all", "DEVICENAME": "所有设备"});
                        } else {
                            $scope.des = [{"DEVICEMODEL": "all", "DEVICENAME": "所有设备"}];
                        }


                        $scope.$apply();
                    });
                }
                $scope.getDeviceType();
                $scope.deed = null;
                $scope.changeType = function () {
                    $scope.device = $scope.deed;
                    $scope.getList();
                    console.log($scope.deed);
//                    $scope.searchTypeStatus = true;
//
//                    base.post("host/changeType", {type: $scope.deed}).get(function (data) {
//                        $scope.changeZt(data);
//                        $scope.lists = data;
//                        $scope.searchTypeStatus = false;
//                    });

                }

                $scope.changeFilter = function () {
                    if ($scope.filterData == "0") {
                        $scope.getList();
                    } else if ($scope.filterData == "1") {
                        $scope.getNoShenHe();
                    } else if ($scope.filterData == "3") {
                        $scope.getShenHe();
                    } else if ($scope.filterData == "4") {
                        $scope.getDaYin();
                    } else if ($scope.filterData == "5") {
                        $scope.getNoResult();
                    }
                }
                $scope.getCharginitem = function () {
                    base.post("host/getCharginitem").get(function (data) {
                        $scope.xms = data;
                    })
                }
                $scope.getReagent = function () {
                    base.post("host/getReagent").get(function (data) {
                        $scope.reagents = data;
                    })
                }
                $scope.getCharginitem();
                //$scope.getReagent();
                $scope.getResult = function (item, event, index) { //获取项目


                    $scope.sgstatus = false;
                    $scope.resultItem = {};
                    $scope.moreImage = [];
                    $(event.target).parent().siblings().removeClass("bg-success");
                    $(event.target).parent().addClass("bg-success");
                    $(event.target).removeClass("bg-success");
                    $scope.checkpt = item.RESULTSTATUS;
                    $scope.sample_index = index;
                    $scope.samplepk = item.PK;
                    if (item.RESULTSTATUS == "已审核" || item.RESULTSTATUS == "已打印") {
                        $scope.sh_status = true;
                    } else {
                        $scope.sh_status = false;
                    }


                    base.post("host/getResult", {UUID: item.UUID}).get(function (data) {

                        $scope.info = {};
                        $scope.info.SEX = "男";
                        //console.log('getResult=' + (new Date().getTime() - t));
                        $scope.UUID = item.UUID;
                        $scope.sampleNo = item.SAMPLENO;
                        $scope.samplepk = item.PK;
                        // console.log($scope.samplepk + "=" + item.PK);
                        WBC = [], RBC = [], PLT = [], BASO = [], DIFF = [], SRET = [], SWDF = [], SWNR = [];

                        $scope.sh_wbc = false;
                        $scope.sh_rbc = false;
                        $scope.sh_plt = false;
                        $scope.sh_diff = false;
                        $scope.sh_baso = false;
                        $scope.zftchart = false;
                        $scope.sh_sret = false;
                        $scope.sh_swdf = false;
                        $scope.sh_swnr = false;
                        for (var i = 0; i < data.length; i++) {
                            //data[i].TESTRESULT
                            if (data[i].TESTRESULT == 'NaN') {
                                data[i].TESTRESULT = "";
                            }

                            if (data[i].RESULTFLAG == "4") {
                                $scope.moreImage.push("data:image/jpg;base64," + data[i].TESTRESULT);
                            }
                            //console.log(data[i].TESTID);
                            if (data[i].TESTID == 'image#WBC') {

                                $scope.sh_wbc = true;
                                if (data[i].RESULTFLAG == '2') {
                                    WBC = data[i].TESTRESULT;
                                } else if (data[i].RESULTFLAG == '3') {
                                    var wbcs = data[i].TESTRESULT.split(",");
                                    for (s in wbcs) {
                                        WBC.push([parseFloat($.trim(wbcs[s]).split(" ")[0]), parseFloat($.trim(wbcs[s]).split(" ")[1])]);
                                    }
                                } else {
                                    WBC = data[i].TESTRESULT.split(" ");

                                }


                            } else if (data[i].TESTID == 'image#RBC') {
                                $scope.sh_rbc = true;
                                if (data[i].RESULTFLAG == '2') {
                                    RBC = data[i].TESTRESULT;
                                } else {
                                    RBC = data[i].TESTRESULT.split(" ");
                                }

                            } else if (data[i].TESTID == 'image#PLT') {
                                $scope.sh_plt = true;
                                if (data[i].RESULTFLAG == '2') {
                                    PLT = data[i].TESTRESULT;
                                } else {
                                    PLT = data[i].TESTRESULT.split(" ");
                                }

                            } else if (data[i].TESTID == 'image#DIFF') {
                                $scope.sh_diff = true;
                                if (data[i].RESULTFLAG == '2') {
                                    DIFF = data[i].TESTRESULT;
                                }
                                if (data[i].RESULTFLAG == '3') {
                                    var diffs = data[i].TESTRESULT.split(",");
                                    for (s in diffs) {
                                        DIFF.push([parseFloat($.trim(diffs[s]).split(" ")[0]), parseFloat($.trim(diffs[s]).split(" ")[1])]);
                                    }
                                } else {
                                    DIFF = data[i].TESTRESULT.split(" ");
                                }

                            } else if (data[i].TESTID == 'image#BASO') {
                                $scope.sh_baso = true;
                                if (data[i].RESULTFLAG == '3') {
                                    var basos = data[i].TESTRESULT.split(",");
                                    for (s in basos) {
                                        BASO.push([parseFloat($.trim(basos[s]).split(" ")[0]), parseFloat($.trim(basos[s]).split(" ")[1])]);
                                    }
                                } else if (data[i].RESULTFLAG == '2') {
                                    BASO = data[i].TESTRESULT;
                                }

                            } else if (data[i].TESTID == 'image#SWDF') {
                                $scope.sh_swdf = true;
                                if (data[i].RESULTFLAG == '2') {
                                    SWDF = data[i].TESTRESULT;
                                }

                            } else if (data[i].TESTID == 'image#SWNR') {
                                $scope.sh_swnr = true;
                                if (data[i].RESULTFLAG == '2') {
                                    SWNR = data[i].TESTRESULT;
                                }

                            } else if (data[i].TESTID == 'image#SRET') {
                                $scope.sh_sret = true;
                                if (data[i].RESULTFLAG == '2') {
                                    SRET = data[i].TESTRESULT;
                                }

                            }

                            if (!isNaN(data[i].TESTRESULT) && data[i].TESTRESULT.indexOf('-') == -1 && data[i].TESTRESULT.indexOf('+') == -1) {
                                  if (data[i].MREFLO0) {
                                    var lower = data[i].MREFLO0;
                                    var hight = data[i].MREFHI0;
                                    var lh = lower + "-" + hight;
                                    data[i].fanwei = lh;
                                    // console.log(data[i].fanwei +""+data[i].)
                                    console.log((parseFloat(data[i].TESTRESULT) < parseFloat(data[i].MREFLO0)) + " " + parseFloat(data[i].TESTRESULT) + " " + data[i].MREFLO0)
                                    if (parseFloat(data[i].TESTRESULT) < parseFloat(data[i].MREFLO0)) {
                                        //console.log(data[i].TESTRESULT + "   " + data[i].MREFLO0);
                                        data[i].isActive = true;
                                        data[i].HL_STATUS = "↓";
                                    } else if (parseFloat(data[i].TESTRESULT) > parseFloat(data[i].MREFHI0)) {
                                        data[i].isActive = false;
                                        data[i].HL_STATUS = "↑";

                                    }

                                }
                                var k = 2;
                                if (data[i].Decimalplace) {
                                    k = data[i].Decimalplace;

                                }
                                
                                data[i].TESTRESULT = parseFloat(data[i].TESTRESULT).toFixed(k);
                            }
                        }

                        for (var i in data) {
                            if (!data[i].index) {
                                data[i].index = 999;
                            }
//                                for (var j in $scope.px) {
//                                    if (data[i].ITEMPK == $scope.px[j].TESTPK) {
//                                        if ($scope.px[j].DATA1) {
//
//                                            data[i].index = parseInt($scope.px[j].DATA1);
//                                        } else {
//
//                                            data[i].index = 9999;
//                                        }
//                                    }
//                                }
                        }
                        var d1 = [], d2 = [];
                        var dlist = [];
                        for (var s = 0; s < data.length; s++) {
                            if (data[s].MEASURETIME == data[0].MEASURETIME) {
                                d1.push(data[s]);
                            } else {
                                d2.push(data[s]);
                            }
                        }

                        d1.sort(function (a, b) {
                            return a.index - b.index;
                        });
                        dlist = d1;
                        //console.table(dlist);
                        if (d2.length > 0) {
                            d2.sort(function (a, b) {
                                return a.index - b.index;
                            });
                            dlist = d1.concat(d2);
                        }



                        console.table(dlist);
                        $scope.results = dlist;
                        $scope.resultItem = data[0];
                        $scope.resultItem.sample_index = index;
                        // console.table($scope.results);
                        setTimeout(function () {
                            $scope.renter();
                        }, 1000)
                        if ($scope.moreImage.length > 0) {
                            console.log($scope.moreImage.length);
                            $scope.image_more = true;
                        } else {
                            checkChart();
                        }
                        getInfoForSample(item);
                    })
                    var getInfoForSample = function (item) {
                        base.post("host/getBrInfoUUID", {UUID: item.UUID}).get(function (data) {
                            if (data != "false") {
                                $scope.info = data;
                                $scope.patientpk = data.PK;

                                // $scope.$apply();
                            }
                            if (!$scope.info) {
                                $scope.info = {};
                            }
                            //获取试剂

                            base.post("host/getReagentForDeviceId", {DEVICEID: $scope.resultItem.DEVICEID}).get(function (data) {
                                if (data && data != "false") {
                                    $scope.phs = data;
                                    $scope.zk_REAGENT = data[0];
                                    console.log($scope.phs);
                                }
                            }
                            )

                            //温度
                            if (!$scope.info.ROOM_TEMPERATURE) {
                                $scope.info.ROOM_TEMPERATURE = "25";
                            }
                            //检验医生
                            if (!$scope.info.JYYS) {
                                $scope.info.JYYS = name;
                            }
                            //根据性别修改结果范围
                            if ($scope.info.SEX == '女') {
                                $scope.changeSex("女");
                            }
                            if ($scope.info) {
                                //根据年龄段 获取值的范围
                                checkRange();
                            }
                            //送检时间
                            if (!$scope.info.CUSTOM1) {
                                $scope.info.CUSTOM1 = $scope.sample_date;
                            }
                            if (!$scope.info.SAMPLE) {
                                base.post("host/getDeviceSample", {DEVICEID: $scope.resultItem.DEVICEID}).get(function (data) {
                                    if (data) {
                                        $scope.info.SAMPLE = data.JUDGE;
                                    }
                                })

                            }
                            //console.log( $scope.info.JYYS);
                        });
                    }


                }
                var checkRange = function () {
                    console.log($scope.info);
                    if ($scope.info && $scope.results && $scope.info.AGE && $scope.info.SEX) {

                        var data = $scope.results;
                        for (var i in data) {
                            if (data[i].ranges) {
                                console.log(data[i].ranges);
                                var range = JSON.parse(unescape(data[i].ranges));
                                var item_range = checkAge_sex_range(data[i], range);

                                if (item_range) {
                                    var lower = item_range.min_val;
                                    var hight = item_range.max_val;
                                    var lh = lower + "-" + hight;
                                    data[i].fanwei = lh;

                                    //console.log((parseFloat(data[i].TESTRESULT) < parseFloat(data[i].MREFLO0)) + " " + parseFloat(data[i].TESTRESULT) + " " + data[i].MREFLO0)
                                    if (parseFloat(data[i].TESTRESULT) < parseFloat(lower)) {
                                        //console.log(data[i].TESTRESULT + "   " + data[i].MREFLO0);
                                        data[i].isActive = true;
                                        data[i].HL_STATUS = "↓";
                                    } else if (parseFloat(data[i].TESTRESULT) > parseFloat(hight)) {
                                        data[i].isActive = false;
                                        data[i].HL_STATUS = "↑";

                                    } else {
                                        data[i].isActive = null;
                                        data[i].HL_STATUS = "";
                                    }
                                }
                            }
                        }
                    }
                }

                var checkAge_sex_range = function (item, range) {
                    var age = parseInt($scope.info.AGE);
                    //var item_range={};
                    for (var i in range) {
                        console.log("222333");
                        if (range[i].sex == $scope.info.SEX) {

                            if (range[i].max_age >= age && age >= range[i].min_age) {
                                return range[i];
                                break;
                            }
                        }
                    }
                }
                //监听属性的改变
                $scope.$watch('info.SEX', function () {
                    checkRange();
                });
                $scope.$watch('info.AGE', function () {
                    checkRange();
                });


                var checkChart = function () {

                    $scope.WBC = "";
                    $scope.RBC = "";
                    $scope.PLT = "";
                    $scope.DIFF = "";
                    $scope.BASO = "";
                    $scope.SWNR = "";
                    $scope.SWDF = "";
                    $scope.SRET = "";

                    if (typeof RBC == "string") {
                        $scope.WBC = "data:image/jpg;base64," + WBC;
                        $scope.RBC = "data:image/jpg;base64," + RBC;
                        $scope.PLT = "data:image/jpg;base64," + PLT;
                        $scope.DIFF = "data:image/jpg;base64," + DIFF;
                        $scope.BASO = "data:image/jpg;base64," + BASO;
                        $scope.SWNR = "data:image/jpg;base64," + SWNR;
                        $scope.SWDF = "data:image/jpg;base64," + SWDF;
                        $scope.SRET = "data:image/jpg;base64," + SRET;
                        $scope.zftchart = true;


                    } else {
                        var NEWWBC = [], NEWRBC = [], NEWPLT = [];
                        if (RBC.length > 0) {
                            var WBCindexs = [];
                            for (var i in WBC) {

                                if (WBC.length < 500) {
                                    WBCindexs.push(i);
                                    NEWWBC.push(parseFloat(WBC[i]));
                                }
                            }
                            var RBCindexs = [];
                            console.log(RBC.length + "+++++++++++++++++++++++0000000000000000000000000000");
                            for (var i in RBC) {
                                RBCindexs.push(i);
                                NEWRBC.push(parseFloat(RBC[i]));
                            }
                            var PLTindexs = [];
                            for (var i in PLT) {
                                PLTindexs.push(i);
                                NEWPLT.push(parseFloat(PLT[i]));
                            }
//                        var WBCChart = echarts.init(document.getElementById('wbc'));
//                        var RBCChart = echarts.init(document.getElementById('rbc'));
//                        var PLTChart = echarts.init(document.getElementById('plt'));
//
//                        WBCChart.setOption(getChart("WBC", WBCindexs, WBC));
//                        RBCChart.setOption(getChart("RBC", RBCindexs, RBC));
//                        PLTChart.setOption(getChart("PLT", PLTindexs, PLT));


                        }
                        var baso = false;
                        for (var i in $scope.results) {
                            if ($scope.results[i].TESTID == "BASOR") {
                                baso = true;
                                break;
                            }
                        }
                        if (baso) {
                            $('#wbc').highcharts(getChart2("WBC/BASO", WBCindexs, NEWWBC));
                        } else {

                            if (WBC.length > 500) {
                                $('#wbc').highcharts(getChart3("WBC", WBC));
                            } else {
                                $('#wbc').highcharts(getChart2("WBC", WBCindexs, NEWWBC));
                            }
                        }

                        if (BASO.length > 0) {
                            $('#baso').highcharts(getChart3("BASO", BASO));
                        }
                        if (DIFF.length > 0) {
                            $('#diff').highcharts(getChart3("DIFF", DIFF));
                        }


                        $('#rbc').highcharts(getChart2("RBC", RBCindexs, NEWRBC));
                        $('#plt').highcharts(getChart2("PLT", PLTindexs, NEWPLT, 'PLT'));
                    }

                }

                $scope.getPatList = function () {
                    base.post("host/getPatList").get(function (data) {
                        if (data) {
                            $scope.pats = data;
                        }
                    })
                }

                $scope.getPatList();
                $scope.changeResultStatus = function (index) {

                    if (parseFloat($scope.results[index].TESTRESULT) < parseFloat($scope.results[index].MREFLO0)) {

                        $scope.results[index].isActive = true;
                        $scope.results[index].HL_STATUS = "↓";
                    } else if (parseFloat($scope.results[index].TESTRESULT) > parseFloat($scope.results[index].MREFHI0)) {
                        $scope.results[index].isActive = false;
                        $scope.results[index].HL_STATUS = "↑";
                    } else {
                        $scope.results[index].HL_STATUS = "";
                    }
                }


                $scope.openZT = function () {

                    if ($scope.checkpt == "未审核" || $scope.checkpt == "无结果" || !$scope.checkpt) {
//                    if ($scope.results) {
                        $("#mode3").modal('show');
                        $.post("host/getZT", function (data) {
                            $scope.zts = data;
                            $scope.$apply();
                        });
                    } else {
                        steveAl("已经审核，不能添加组套", 1000);
                    }
                }



                $scope.checked = function () {
                    if ($scope.checkAll == true) {
                        for (var i = 0; i < $scope.lists.length; i++) {
                            $scope.lists[i].check = true;
                        }
                    } else {
                        for (var i = 0; i < $scope.lists.length; i++) {
                            $scope.lists[i].check = false;
                        }
                    }
                }
                $scope.plsz = [];
                $scope.isToo = true;
                var sure_list = [];
                $scope.piLiangSH = function () { //审核
                    for (var i = 0; i < $scope.lists.length; i++) {
                        if ($scope.lists[i].check) {

                            if ($scope.lists[i].RESULTSTATUS == "已审核" || $scope.lists[i].RESULTSTATUS == "已打印") {
                                steveAl("已经审核，请勿重复审核", 1000);
                                return;
                            } else if (!$scope.lists[i].PK) {
                                steveAl("结果没有关联不能审核", 1000);
                                return;
                            } else {
                                sure_list.push($scope.lists[i].PK);
                            }

                        }
                    }

                    if (sure_list.length == 0) {

                        if (!$scope.samplepk || $scope.samplepk == "null") {
                            steveAl("结果没有关联不能审核", 1000);
                        } else {
                            sure_list.push($scope.samplepk);
                        }
                    }


                    if ($scope.isToo && config.checkSure != 'true') {
                        if (sure_list.length > 0) {
                            $("#mode2").modal("show");
                        } else {
                            steveAl("请选择要审核的数据", 1000);
                        }
                    } else {
                        if (sure_list.length > 0) {
                            submitSure();
                        } else {
                            steveAl("请选择要审核的数据", 1000);
                        }

                    }
                    if ($scope.brid == null) {
                        return;
                    }

                }

                var submitSure = function () {

                    base.post("host/piLiangSH", {pks: sure_list.join(",")}).get(function (data) {
                        if (data == 'true') {
                            if (sure_list.length = 1) {
                                $scope.lists[$scope.resultItem.sample_index].RESULTSTATUS = "已审核";
                                $scope.checkpt = "已审核";
                                if (!$scope.info.CHECKOPERATOR) {
                                    $scope.info.CHECKOPERATOR = name;
                                }
                            } else {
                                if ($scope.deed) {
                                    $scope.changeType();
                                } else {
                                    $scope.getList();
                                }
                            }
                            sure_list = [];
                            steveAl("审核成功", 1000);

                        } else if (data == "false") {
                            steveAl("审核失败", 1500);
                        } else {
                            steveAl(data, 1500);
                        }
                    })
                }
                //取消审核
                $scope.cancelSH = function () {
                    base.post("host/cancelSH", {sample_pk: $scope.samplepk}).get(function (data) {
                        if (data == "true") {
                            steveAl("取消审核成功", 1000);
                            $scope.lists[$scope.resultItem.sample_index].RESULTSTATUS = "未审核";
                            $scope.checkpt = "未审核";
                        } else {
                            steveAl(data, 1000);
                        }
                    })
                }
                var hb_list = [];
                $scope.hebing = function () {

                    for (var i = 0; i < $scope.lists.length; i++) {
                        if ($scope.lists[i].check) {

                            if ($scope.lists[i].RESULTSTATUS == "已审核" || $scope.lists[i].RESULTSTATUS == "已打印") {
                                steveAl("已经审核，不能合并", 1000);
                                return;
                            } else {
                                hb_list.push($scope.lists[i].UUID);
                            }

                        }
                    }

                    if (hb_list.length > 1) {

                        hebingToServer();
                    } else {
                        steveAl("请选择要合并的数据", 1000);
                    }



                }

                var hebingToServer = function () {
                    if (!$scope.results) {

                        steveAl("请选择一个合并的主项");

                    } else {
                        steveConfrim("确定合并吗?", function () {
                            var main_uuid = $scope.resultItem.UUID;
                            for (var i = 0; i < hb_list.length; i++) {
                                if (hb_list[i] == main_uuid) {
                                    hb_list.splice(i, 1);
                                    break;
                                }
                            }
                            base.post("host/hebing", {main_uuid: main_uuid, other_uuids: hb_list.join(",")}).get(function (data) {
                                if (data == 'true') {
                                    steveAl("合并成功", 1000);
                                    if ($scope.deed) {
                                        $scope.changeType();
                                    } else {
                                        $scope.getList();
                                    }
                                } else {
                                    steveAl("合并失败", 1000);
                                }
                            })
                        })



                    }
                }
                $scope.checkMm = function () { //检查密码
                    if ($scope.mm) {
                        $.post("host/checkMM", {mm: $scope.mm}, function (data) {
                            if (data == "true") {
                                submitSure();
                                $("#mode2").modal('hide');
                                $scope.isToo = false;
                                setTimeout(function () {
                                    $scope.isToo = true;
                                }, 60000);
                                $scope.mm = null;
                            } else {
                                alert("密码错误!");
                            }
                        });
                    }
                }

//                $("#xiugai").click(function () {
//                    var xg = $("#xiugai").html();
//                    if (xg == "修改病人信息") {
//                        $("#xiugai").html("保存");
//                        $(".cs").removeAttr("");
//                        $("#quxiao").show();
//                    } else {
//                        $("#xiugai").html("修改病人信息");
//                        $(".cs").attr("", "true");
//                        $("#quxiao").hide();
//                        if ($scope.info.PK) {
//                            $.post("host/updateBrXX", {pk: $scope.info.PK, samplepk: $scope.info.samplepk, sample: $scope.info.SAMPLE, brxm: $scope.info.PATIENTNAME,
//                                sex: $scope.info.SEX, age: $scope.info.AGE, ks: $scope.info.SECTION, STAYHOSPITALMODE: $scope.info.STAYHOSPITALMODE,
//                                ch: $scope.info.BED_NO, lczd: $scope.info.DIAGNOSTIC, brpk: $scope.pppk, jyys: $scope.JYYS, sjys: $scope.SJYS}, function (data) {
//                                if (data == "true") {
//                                    steveAl("修改成功!", 1000);
//                                } else {
//                                    steveAl("修改失败!", 1000);
//                                }
//                            });
//                        }
//                    }
//                })
//                $("#quxiao").click(function () {
//                    $("#xiugai").html("修改病人信息");
//                    $(".cs").attr("", "true");
//                    $("#quxiao").hide();
//                });
//                $("#bbly").change(function(){
//                    var ly=$("#bbly").val();
//                    if(ly=='1'){
//                        $("#tt").html('住院号:<input type="text"/>');
//                    }else{
//                        $("#tt").html('门诊号:<input type="text"/>');
//                    }
//                });
                $scope.searchPatientId = function (event) {
                    if (event.keyCode == 13) {
                        $scope.searchPid();
                    }
                }
                $scope.searchPid = function () {
                    if ($scope.info.PATIENTID) {
                        base.post("host/getBrInfo", {PATIENTID: $scope.info.PATIENTID}).get(function (data) {
                            if (data != "false") {
                                if (data instanceof Array) {

                                    if (data.length == 1) {
                                        $scope.info = data[0];

                                        $scope.patientpk = data.PK;
                                    } else if (data.length > 1) {
                                        $scope.infos = data;
                                        $(".modal-info").modal('show');
                                    }

                                } else {
                                    $scope.info = data;
                                    $scope.patientpk = data.PK;
                                    //获取试剂

                                    base.post("host/getReagentForDeviceId", {DEVICEID: $scope.resultItem.DEVICEID}).get(function (data) {
                                        if (data && data != "false") {
                                            $scope.phs = data;
                                            $scope.zk_REAGENT = data[0];
                                        }
                                    }
                                    )

                                    //温度
                                    if (!$scope.info.ROOM_TEMPERATURE) {
                                        $scope.info.ROOM_TEMPERATURE = "25";
                                    }
                                    //检验医生
                                    if (!$scope.info.JYYS) {
                                        $scope.info.JYYS = name;
                                    }
                                    //根据性别修改结果范围
                                    if ($scope.info.SEX == '女') {
                                        $scope.changeSex("女");
                                    }

                                    if (!$scope.info.SAMPLE) {
                                        base.post("host/getDeviceSample", {DEVICEID: $scope.resultItem.DEVICEID}).get(function (data) {
                                            if (data) {
                                                $scope.info.SAMPLE = data.JUDGE;
                                            }
                                        });

                                    }
                                }
                                //  $scope.$apply();
                            } else {
                                steveAl("没有找到病历号!", 1000);
                            }
                        })
                    }

                }
                $scope.selectInfo = function (info) {
                    $scope.info = info;
                    //获取试剂
                    if ($scope.info.REAGENT) {
                        base.post("host/getReagentForDeviceId", {DEVICEID: $scope.resultItem.DEVICEID}).get(function (data) {
                            if (data && data != "false") {
                                $scope.phs = data;
                                $scope.zk_REAGENT = data[0];
                            }
                        }
                        )
                    }
                    //温度
                    if (!$scope.info.ROOM_TEMPERATURE) {
                        $scope.info.ROOM_TEMPERATURE = "25";
                    }
                    //检验医生
                    if (!$scope.info.JYYS) {
                        $scope.info.JYYS = name;
                    }
                    //根据性别修改结果范围
                    if ($scope.info.SEX == '女') {
                        $scope.changeSex("女");
                    }
                    $scope.info.CUSTOM1 = $scope.sample_date;
                    //根据年龄段获取值范围
                    checkRange();

                    if (!$scope.info.SAMPLE) {
                        base.post("host/getDeviceSample", {DEVICEID: $scope.resultItem.DEVICEID}).get(function (data) {
                            if (data) {
                                $scope.info.SAMPLE = data.JUDGE;
                            }
                        });

                    }
                    $(".modal-info").modal('hide');
                }
                $scope.searchBarcode = function (event) {
                    if (event.keyCode == 13) {
                        $scope.searchBar();
                    }
                }
                $scope.searchBar = function () {
                    if ($scope.info.BARCODE) {
                        base.post("host/getBrInfoTmh", {BARCODE: $scope.info.BARCODE}).get(function (data) {
                            if (data != "false") {
                                $scope.info = data;

                                $scope.patientpk = data.PK;
//                                    $scope.yblb=data.YBLB;
//                                    $scope.$apply();
                            } else {
                                steveAl("没有找到条码号!", 1000);
                            }
                        })
                    }
                }


                $scope.info = null;
                $scope.saveInfo = function (patInfo) { //保存

                    if (patInfo.$invalid) {
                        steveAl("请补全病人信息", 1000);
                        return;
                    }

                    //同时保存多个

                    var saveuuidList = [];
                    //获取多项删除数据 

                    for (var i = 0; i < $scope.lists.length; i++) {
                        if ($scope.lists[i].check) {
                            console.log($scope.lists[i].RESULTSTATUS)
                            if ($scope.lists[i].RESULTSTATUS == "已审核" || $scope.lists[i].RESULTSTATUS == "已打印") {
                                steveAl("已经审核，不能保存", 1000);
                                return;
                            } else {
                                saveuuidList.push({"sampleNo": $scope.lists[i].SAMPLENO, "uuid": $scope.lists[i].UUID});
                            }

                        }
                    }

                    if (saveuuidList.length > 1) {
                        base.post("host/saveMany", {patInfo: angular.toJson($scope.info), uuids: angular.toJson(saveuuidList), patientpk: $scope.patientpk})
                                .get(function (data) {
                                    if (data == "true") {
                                        if ($scope.deed) {
                                            $scope.changeType();
                                        } else {
                                            $scope.getList();
                                        }

                                        steveAl("保存成功", 1000);
                                    }
                                })


                    } else {

                        if (!$scope.sgstatus & !$scope.results) {
                            if (!$scope.UUID) {
                                steveAl("请选择对应的结果", 1000);
                                return;
                            }
                        }
                        //console.log($scope.results);
                        var sgDevice_name;
                        if ($scope.sgDevice) {
                            sgDevice_name = $scope.sgDevice.NOTES;
                        }
                        base.post("host/saveResult", {sgDevice: sgDevice_name, sgstatus: $scope.sgstatus, patInfo: angular.toJson($scope.info), results: angular.toJson($scope.results), UUID: $scope.UUID, sampleNo: $scope.sampleNo, patientpk: $scope.patientpk})
                                .get(function (data) {
                                    if (data != "false") {//                                      
                                        if ($scope.resultItem && $scope.resultItem.sample_index) {
                                            angular.extend($scope.lists[$scope.resultItem.sample_index], $scope.info, data);
                                            //$scope.info.samplepk
                                            $scope.lists[$scope.resultItem.sample_index].RESULTSTATUS = "未审核";
                                            $scope.UUID = $scope.lists[$scope.resultItem.sample_index].UUID;
                                            $scope.sampleNo = $scope.lists[$scope.resultItem.sample_index].SAMPLENO;

                                            $scope.samplepk = $scope.lists[$scope.resultItem.sample_index].PK;
                                            console.log($scope.lists[$scope.resultItem.sample_index]);
                                        } else {
                                            if ($scope.deed) {
                                                $scope.changeType();
                                            } else {
                                                $scope.getList();
                                            }
                                        }
                                        steveAl("保存成功", 1000);
                                    }
                                })
                    }




                }

                $scope.savesg = function () {
                    console.log($scope.results.length == 0);
                    if (!$scope.sgstatus || $scope.results.length == 0) {
                        steveAl("请添加手工项目", 1000);
                        return;
                    }
                    $(".modal-sg").modal("show");
                }

                $scope.save_sg_to_server = function () {
                    if ($scope.sgDevice) {
                        base.post('host/saveSg', {sgDevice: $scope.sgDevice.NOTES, data: angular.toJson($scope.results), count: $scope.sg_count}).get(function (data) {
                            if (data == 'true') {
                                steveAl("保存成功", 1000);
                                $scope.getList();
                                $(".modal-sg").modal("hide");
                            }
                        })
                    } else {
                        steveAl("请选择手工类型", 1000);
                    }

                }
                $scope.deleteInfo = function () { //删除匹配信息
                    var deleteuuidList = [];
                    //获取多项删除数据 

                    for (var i = 0; i < $scope.lists.length; i++) {
                        if ($scope.lists[i].check) {
                            console.log($scope.lists[i].RESULTSTATUS)
                            if ($scope.lists[i].RESULTSTATUS == "已审核" || $scope.lists[i].RESULTSTATUS == "已打印") {
                                steveAl("已经审核，不能删除", 1000);
                                return;
                            } else {
                                deleteuuidList.push($scope.lists[i].UUID);
                            }

                        }
                    }

                    if (deleteuuidList.length == 0) {
                        if ($scope.checkpt == "未审核" || $scope.checkpt == "无结果") {
                            deleteuuidList.push($scope.UUID);
                        } else {
                            steveAl("已审核不能进行删除!", 1000);
                        }
                    }

                    if (deleteuuidList.length != 0) {
                        steveConfrim("你确定删除样本吗？", function () {
                            base.post("host/deleteInfo", {UUID: deleteuuidList.join(",")}).get(function (data) {
                                if (data == "true") {
                                    if ($scope.deed) {
                                        $scope.changeType();
                                    } else {
                                        $scope.getList();
                                    }
                                    $scope.results = [];
                                    $scope.info = {};
                                } else {
                                    alert("删除失败!")
                                }
                            })

                        })
                    }

//                    if ($scope.checkpt == "未审核" || $scope.checkpt == "无结果") {
//                        steveConfrim("你确定删除样本 " + $scope.sampleNo + " 吗？", function () {
//                            base.post("host/deleteInfo", {UUID: $scope.UUID, pk: $scope.pppk}).get(function (data) {
//                                if (data == "true") {
//                                    $scope.getList();
//                                    $scope.results = [];
//                                    $scope.info = {};
//                                } else {
//                                    alert("删除失败!")
//                                }
//                            })
//
//                        })
//                    } else {
//                        steveAl("已审核不能进行删除!", 1000);
//                    }

                }

                $scope.shougong = function () {
                    $scope.results = [];
                    $scope.checkpt = "";
                    // 是否为手工项目
                    $scope.sgstatus = true;
                    $scope.info = {};
                    $scope.resultItem = {DEVICEID: "MB"};
                    $(".xl_info").find(".bg-success").removeClass("bg-success");
                    $(".sg_device").modal("show");
                    getSgDevice();
                }
                // 获取手工项目设备名称
                var getSgDevice = function () {
                    base.post("host/getSgDevice").get(function (data) {
                        console.log(data);
                        if (data) {
                            $scope.sgDevices = data;
                            $scope.sgDevice = data[0];
                        }
                    })
                };
                $scope.changeSgDevice = function () {
                    console.log($scope.sgDevice);
                    $scope.resultItem = {DEVICEID: $scope.sgDevice.DEVICEMODEL};

                }


                $scope.insertOne = function () { //添加项目新增一行

                    if ($scope.results.length > 0 && $scope.checkpt) {
                        if ($scope.checkpt == "未审核" || $scope.checkpt == "无结果") {
                            var t = {C: "", T: "0", e: "0", U: "l", RESULTFLAG: "0"};
                            $scope.results.unshift(t);
                            //$scope.$apply();
                            console.log($scope.results);
                            setTimeout(function () {
                                $scope.renter();
                            }, 500);
                        } else {
                            steveAl("已审核不能添加项目!", 1000);
                        }
                    } else {

                        var t = {C: "", T: "0", e: "0", U: "l", RESULTFLAG: "0"};
                        $scope.results.unshift(t);

                        //console.log($scope.results);
                        setTimeout(function () {
                            $scope.renter();
                        }, 300);
                    }
                }
//                $scope.djResult=function(item,event,index){//单机项目
//                    $scope.xmpk=item;
//                    $scope.yindex=index;
//                }
                $scope.deleteXM = function (item, index) {  //删除项目
                    if ($scope.checkpt == "未审核" || $scope.checkpt == "无结果" || !$scope.checkpt) {
                        steveConfrim("确定删除  吗？", function () {
                            $.post("host/deleteXM", {pk: item.PK}, function (data) {
                                if (data == "true") {
                                    steveAl("删除成功!", 1000);
                                    $scope.results.splice(index, 1);
                                    $scope.$apply();
                                } else {
                                    $scope.results.splice(index, 1);
                                    $scope.$apply();
                                    //steveAl("删除失败!", 1000);
                                }
                            })
                        })
                    } else {
                        steveAl("已审核不能进行删除!", 1000);
                    }
                }


                $scope.printJG = function () {  //打印
                    var flag = printMore();
                    if (flag == 3) {
                        if ($scope.checkpt == "已审核" || $scope.checkpt == "已打印") {
                            var date = new Date().Format("yyyy-MM-dd hh:mm:ss");
                            base.post("host/printReport", {pk: $scope.samplepk, time: date, device: $scope.resultItem.DEVICEID}).get(function (data) {

                                if (data == "false") {
                                    steveAl("打印出错", 1000);
                                    // $scope.getList();

                                } else {

                                    $scope.lists[$scope.sample_index].RESULTSTATUS = "已打印";

                                    try {
                                        if (data.length) {
                                            localStorage.reprotConfig = JSON.stringify(angular.fromJson(unescape(data)));
                                        }
                                    } catch (e) {

                                    }

                                    localStorage.results = JSON.stringify($scope.results);
                                    localStorage.sampleNo = $scope.sampleNo;
                                    localStorage.date = date;
                                    localStorage.info = JSON.stringify($scope.info);
                                    var flagRpt = true;
                                    var count = 0;
                                    if ($scope.resultItem.DEVICEID == 'AVE-752') {
                                        window.open("fomatRpt_1.jsp");
                                    } else {

                                        for (i in $scope.results) {
                                            var test_id = $scope.results[i].TESTID;
                                            if (test_id && test_id.indexOf('image') > -1) {
                                                count = count + 1;
                                            }
                                        }
                                        if (count > 3) {
                                            window.open("printReport-1-4image.jsp");

                                        } else {
                                            window.open("printReport-1-4image.jsp");
                                        }
                                    }
                                }
                            })
                        } else {
                            steveAl("未审核不能进行打印!", 1000);
                        }
                    } else if (flag == 2) {
                        window.open("host/autoRpt");
                    }
                }
                var printMore = function () {
                    //alert("1");
                    var printList = [];
                    for (var i = 0; i < $scope.lists.length; i++) {
                        if ($scope.lists[i].check) {

                            if ($scope.lists[i].RESULTSTATUS == "未审核") {
                                steveAl("未审核不能打印", 1000);
                                return 1;
                            } else if (!$scope.lists[i].PK) {
                                steveAl("结果没有关联不能审核", 1000);
                                return 1;
                            } else {
                                printList.push($scope.lists[i].UUID);
                            }

                        }
                    }

                    console.log("piliang daying");
                    if (printList.length > 1) {
                        console.log(JSON.stringify(printList));
                        window.localStorage.rpts = JSON.stringify(printList);
                        return 2;
                    } else {
                        return 3;
                    }
                }

                $scope.saveZkData = function () {

                    if ($scope.zk_REAGENT) {
                        steveConfrim("确定保存为质控数据？", function () {
                            base.post("host/saveZk", {sample_date: $scope.sample_date, results: angular.toJson($scope.results), ZK_REAGENT_PK: $scope.zk_REAGENT.PK, BATCH_NUMBER: $scope.zk_REAGENT.BATCH_NUMBER}).get(function (data) {
                                if (data == 'true') {
                                    steveAl("保存成功", 1000);
                                }
                                $scope.getList();
                            })
                        }, true);
                    } else {
                        steveAl("请选择试剂");
                    }

                };

                $scope.clickZT = function (it, event) {
                    $scope.checkZT = it;
                    $(event.target).parent().siblings().removeClass("danger");
                    $(event.target).parent().addClass("danger");
                }
                $scope.addZT = function (mytype) { //添加组套

                    if ($scope.checkZT) {
                        $.post("host/getZTMX", {id: $scope.checkZT.ITEMID, deviceid: $scope.resultItem.DEVICEID}, function (data) {
                            for (var i = 0; i < data.length; i++) {
                                for (var j = 0; j < $scope.results.length; j++) {
                                    if (data[i].TESTID == $scope.results[j].TESTID) {
                                        data[i].TESTRESULT = $scope.results[j].TESTRESULT;
                                    }
                                }
                            }
                            if (!$scope.sgstatus) {
                                var samp = $scope.resultItem.SAMPLENO;
                                var de = $scope.resultItem.DEVICEID;
                                var me = $scope.resultItem.MEASURETIME;
                                var type = $scope.resultItem.SAMPLETYPE;
                                var uuid = $scope.resultItem.UUID;
                            }

                            if (mytype == 'replace') {
                                console.log("替换");
                                $scope.results = [];
                            }
                            for (var i = 0; i < data.length; i++) {
                                var t_flag = true;
                                for (var n in $scope.results) {
                                    if ($scope.results[n] && $scope.results[n].TESTID == data[i].TESTID) {
                                        t_flag = false;
                                        break;
                                    }
                                }
                                if (t_flag) {
                                    var f = {}
                                    f.TESTID = data[i].TESTID;
                                    f.ITEMPK = data[i].PK;
                                    f.CHINESENAME = data[i].CHINESENAME;
                                    f.UNIT = data[i].UNIT;
                                    f.RESULTFLAG = "0";// 必须设置为0 否则会过滤掉
                                    f.TESTRESULT = data[i].TESTRESULT;
                                    if (data[i].MREFLO0) {
                                        var lower = data[i].MREFLO0;
                                        var hight = data[i].MREFHI0;
                                        var lh = lower + "-" + hight;
                                        if (lower && hight) {
                                            f.fanwei = lh;
                                        } else if (lower) {
                                            f.fanwei = lower;
                                        } else if (hight) {
                                            f.fanwei = lower;
                                        }

                                    }
                                    if (!$scope.sgstatus) {
                                        f.UUID = uuid;
                                        f.SAMPLETYPE = type;
                                        f.SAMPLENO = samp;
                                        f.DEVICEID = de;
                                        f.MEASURETIME = me;
                                        f.TESTRESULT = data[i].TESTRESULT;
                                    }
                                    $scope.results.push(f);
                                    $scope.$apply();
                                }
                            }
                        });
                        $("#mode3").modal('hide');
                        setTimeout(function () {
                            $scope.renter();
                        }, 300);
                    } else {
                        steveConfrim("请选择组套");
                    }
                }


                $(".key").each(function (index) {
                    var myindex = index;
                    $(this).keyup(function (event) {
                        console.log(event.keyCode);
                        if (event.keyCode == 13) {
                            $(".key")[myindex + 1].focus();
//                            var e = jQuery.Event("keypress");//模拟一个键盘事件
//                            e.keyCode = 9;//keyCode=13是回车
//                            console.log("出发 tab");
//                            $(this).trigger(e);
                        }
                    })
                })


                $scope.renter = function () {
                    $('.xx').autocomplete({
                        source: function (query, process) {
                            var matchCount = this.options.items;
//                    var products=[{"code":"1","name":"test"},{"code":"2","name":"test"},{"code":"3","name":"test"}];
//                     process(products);
                            // alert(matchCount);
                            console.log($scope.resultItem.DEVICEID + "-----------------");
                            $.post("host/xmquery", {"py": query, "matchCount": matchCount, deviceid: $scope.resultItem.DEVICEID}, function (respData) {
                                process(respData);
                            });
                        },
//              focusSearch:true,
                        menu: "<table style='width:300px' class='table table-bordered typeahead dropdown-menu'></table>",
                        item: "<tr></tr>",
                        thisHtml: "<tr><th>拼音</th><th>项目</th></tr>",
                        formatItem: function (item) {
                            return "<td>" + item.TESTID + "</td><td>" + item.CHINESENAME + "</td>";
                        },
                        setValue: function (item) {

                            return {'data-value': item["CHINESENAME"], 'real-value': JSON.stringify(item)};
                        },
                        select: function () {

                            try {
                                var val = this.$menu.find('.active').attr('data-value')
                                var realVal = this.$menu.find('.active').attr('real-value');
                                this.$element
                                        .val(this.updater(val)).attr("real-value", realVal)
                                        .change();
                                var n = this.$element.attr("myindex");
                                realVal = JSON.parse(realVal);
                                $scope.$apply(function () {
                                    for (var i = 0; i < $scope.results.length; i++) {
                                        if ($scope.results[i].ITEMPK == realVal.PK) {
                                            alert("不可以添加重复项目!");
                                            $scope.results[n].CHINESENAME = null;
                                            return;
                                        }
                                    }
                                    console.log(realVal);
                                    if ($scope.hcpk == null) {
                                        $.post("host/getMaxPK", function (data) {
                                            $scope.hcpk = data.PK;

                                        });
                                    } else {
                                        $scope.hcpk++;
                                    }
                                    setTimeout(function () {
                                        $scope.results[n].PK = $scope.hcpk;
                                    }, 300);


                                    $scope.results[n].CHINESENAME = realVal.CHINESENAME;
                                    $scope.results[n].ITEMPK = realVal.PK;
                                    $scope.results[n].TESTID = realVal.TESTID;
                                    $scope.results[n].UNIT = realVal.UNIT;
                                    $scope.results[n].TESTRESULT = realVal.DATA2;
                                    $scope.results[n].SAMPLENO = $scope.resultItem.SAMPLENO;
                                    $scope.results[n].DEVICEID = $scope.resultItem.DEVICEID;
                                    $scope.results[n].UUID = $scope.resultItem.UUID;
                                    $scope.results[n].FEE = $scope.resultItem.FEE;

                                    $scope.results[n].SAMPLETYPE = $scope.resultItem.SAMPLETYPE;
                                    $scope.results[n].MEASURETIME = $scope.resultItem.MEASURETIME;
                                    var lower = realVal.MREFLO0;
                                    var hight = realVal.MREFHI0;
                                    var lh = lower + "-" + hight;

                                    if (lower && hight) {
                                        $scope.results[n].fanwei = lh;
                                    } else if (lower) {
                                        $scope.results[n].fanwei = lower;
                                    } else if (hight) {
                                        $scope.results[n].fanwei = lower;
                                    }

                                    console.log($scope.results[n]);
                                });
                                return this.hide()
                            } catch (e) {
                                console.log(e);
                                return this.hide();
                            }

                        }
                    })


                    $('.yy').autocomplete({
                        clickSearch: true,
                        searchAttr: "autoSearch",
                        source: function (query, process) {
                            var matchCount = this.options.items;
//                    var products=[{"code":"1","name":"test"},{"code":"2","name":"test"},{"code":"3","name":"test"}];
//                     process(products);
                            // alert(matchCount);

                            $.post("host/queryItemValue", {"TESTID": query, "matchCount": matchCount}, function (respData) {
                                process(respData);
                            });
                        },
//              focusSearch:true,
                        menu: "<table style='width:300px' class='table table-bordered typeahead dropdown-menu'></table>",
                        item: "<tr></tr>",
                        thisHtml: "<tr><th>名称</th></tr>",
                        formatItem: function (item) {
                            return "<td>" + item.MREFVAL0 + "</td>";
                        },
                        setValue: function (item) {

                            return {'data-value': item["MREFVAL0"], 'real-value': JSON.stringify(item)};
                        },
                        select: function () {

                            try {
                                var val = this.$menu.find('.active').attr('data-value')
                                var realVal = this.$menu.find('.active').attr('real-value');
                                this.$element
                                        .val(this.updater(val)).attr("real-value", realVal)
                                        .change();
                                var n = this.$element.attr("myindex");
                                realVal = JSON.parse(realVal);
                                $scope.$apply(function () {
//                                    for (var i = 0; i < $scope.results.length; i++) {
//                                        if ($scope.results[i].ITEMPK == realVal.PK) {
//                                            alert("不可以添加重复项目!");
//                                            $scope.results[n].CHINESENAME = null;
//                                            return;
//                                        }
//                                    }
//                                    console.log(realVal);
//                                    if ($scope.hcpk == null) {
//                                        $.post("host/getMaxPK", function (data) {
//                                            $scope.hcpk = data.PK;
//                                            console.log("---发送---");
//                                        });
//                                    } else {
//                                        $scope.hcpk++;
//                                    }
                                    setTimeout(function () {
                                        $scope.results[n].TESTRESULT = realVal.MREFVAL0;
                                    }, 300);
//                                    $scope.results[n].CHINESENAME = realVal.CHINESENAME;
//                                    $scope.results[n].ITEMPK = realVal.PK;
//                                    $scope.results[n].TESTID = realVal.TESTID;
//                                    $scope.results[n].UNIT = realVal.UNIT;
//                                    $scope.results[n].SAMPLENO = $scope.resultItem.SAMPLENO;
//                                    $scope.results[n].DEVICEID = $scope.resultItem.DEVICEID;
//                                    $scope.results[n].UUID = $scope.resultItem.UUID;
//                                    $scope.results[n].FEE = $scope.resultItem.FEE;
//                                    $scope.results[n].SAMPLETYPE = $scope.resultItem.SAMPLETYPE;
//                                    $scope.results[n].MEASURETIME = $scope.resultItem.MEASURETIME;
                                });
                                return this.hide()
                            } catch (e) {
                                return this.hide();
                            }

                        }
                    })
                }


                //日期
                layui.use('laydate', function () {
                    var laydate = layui.laydate;

                    var start = {
                        istoday: true
                        , choose: function (datas) {
                            $scope.sample_date = datas;
                            $scope.changeSampleDate();

                        }
                    };
                    $scope.sample_date = laydate.now();
                    //$scope.$apply();
                    document.getElementById('sample_date').onclick = function () {
                        start.elem = this;
                        laydate(start);
                    }


                });
                //直方图

                $scope.renter();
            })





    function autoHeight() {
        var bHeight = $('body').height();


        $(".tab-content").height(bHeight - 130);

    }
    autoHeight();


    $(window).resize(function () {
        autoHeight();
    });
</script>
